package fm.last.api
{
    import flash.net.URLRequestMethod;
    import flash.net.URLVariables;
    
    import fm.last.Agent;
    import fm.last.RestAPI;
    
    final public class PlaylistAPI extends RestAPI
    {
        // those in comment are not implemented yet
        public static const PLAYLIST_ADD_TRACK:String = "playlist.addTrack";
        public static const PLAYLIST_CREATE:String    = "playlist.create";
        public static const PLAYLIST_FETCH:String     = "playlist.fetch";
        
        public function PlaylistAPI(agent:Agent)
        {
            super(agent);
        }

        /* ********************************************************************/
        

        /** playlist.addTrack */
        public function addTrack(onComplete:Function,
                                  onError:Function,
                                  playlistID:String,
                                  artist:String,
                                  track:String):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = PlaylistAPI.PLAYLIST_ADD_TRACK;
            urlVars["playlistID"] = playlistID;  
            urlVars["artist"]     = artist;
            urlVars["track"]      = track;                       
            requestAPI(URLRequestMethod.POST, urlVars, true, onComplete, onError);
        }
        

        /** playlist.create */
        public function create(onComplete:Function,
                                  onError:Function,
                                  title:String,
                                  description:String=null):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = PlaylistAPI.PLAYLIST_CREATE;
            urlVars["title"] = title;  
            if (description!=null) urlVars["description"] = description;                      
            requestAPI(URLRequestMethod.POST, urlVars, true, onComplete, onError);
        }
        
        

        /** playlist.fetch */
        public function fetch(onComplete:Function,
                                  onError:Function,
                                  playlistURL:String):void
        {
            var urlVars:URLVariables = new URLVariables();
            urlVars["method"] = PlaylistAPI.PLAYLIST_FETCH;
            urlVars["playlistURL"] = playlistURL;                        
            requestAPI(URLRequestMethod.GET, urlVars, false, onComplete, onError);
        }
        
        
    }
}